﻿using System;
using System.Collections.Generic;
using System.Text;

namespace 观察者模式
{
    public class CurrentDisplay :IDisplayBoard, IObserver
    {
        public double Temperature { get; set; }
        public double Humidity { get; set; }
        public ISubject Subject { get; }

        public CurrentDisplay(ISubject subject)
        {
            Subject = subject;
            Subject.AddObserver(this);
        }
        public void Update(ISubject obj, object arg)
        {
            dynamic data = arg;
            Temperature = data.Temperature;
            Humidity = data.Humidity;

            Display();
        }

        public void Display()
        {
            Console.WriteLine($"{nameof(Temperature)}:{Temperature.ToString(".##")},{nameof(Humidity)}:{Humidity.ToString(".##")}");
        }
    }
}
